package com.graduationproject.controller;


import com.graduationproject.common.R;
import com.graduationproject.entity.Dish;
import com.graduationproject.entity.Menu;
import com.graduationproject.entity.dto.DishUserDTO;
import com.graduationproject.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2025-08-21
 */
@RestController
@RequestMapping("api/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    /**
     * 向菜单里添加菜品
     *
     * @param menu
     * @return
     */
    @PostMapping("/addMenu")
    public R<String> addMenu(@RequestBody Menu menu) {
        menuService.addMenu(menu);
        return R.success("添加成功");
    }

    /**
     * 查询菜单中的菜品信息
     *
     * @return
     */
    @GetMapping("/getMenu/{username}")
    public R<List<Menu>> getMenu(@PathVariable String username) {
        List<Menu> dishInfo = menuService.getMenu(username);
        return R.success(dishInfo);
    }

    /**
     * 根据id删除菜单中的菜品
     *
     * @param row
     * @return
     */
    @DeleteMapping("/menuDelete/{row}")
    public R<String> menuDelete(@PathVariable int row) {
        menuService.menuDelete(row);
        return R.success("删除成功");
    }

    /**
     * 清空菜单
     *
     * @param username
     * @return
     */
    @DeleteMapping("/deleteAll/{username}")
    public R<String> deleteAll(@PathVariable String username) {
        menuService.deleteAll(username);
        return R.success("删除成功");
    }
}
